package Retail;


import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RetailProductDelete extends HttpServlet {
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doProcess(req,resp);
	}

	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doProcess(req,resp);
	}
	protected void doProcess(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String InputText= req.getParameter("ProductID");
		System.out.print("ERIC" + InputText);
		if (InputText != null){	
		try {
			Class.forName("org.h2.Driver");
			Connection con = DriverManager.getConnection("jdbc:h2:~/retail",
					"sa", "");
			PreparedStatement ps = con.prepareStatement("Delete FROM PRODUCT Where PRODUCTID=?");
		    ps.setString(1, InputText);
			ps.executeUpdate();
	

			ps.close();
			con.close();
			
			resp.sendRedirect("Product/ProductMain.jsp");	
			
		}catch (ClassNotFoundException e) {
			resp.sendRedirect("Product/ProductNotFound.jsp");	
		} catch (SQLException e) {
			resp.sendRedirect("Product/ProductNotFound.jsp");	
		}
		}

		
	}

}
